﻿using Ln.Fram.SqlSugarCore.Abstractions;
using Ln.Rbac.Domain.Entities;
using Ln.Rbac.Domain.Shared.Enums;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;

namespace Ln.Rbac.SqlSugarCore.DataSeeds;

public class RoleDataSeed : IDataSeedContributor, ITransientDependency
{
	#region 构造函数
	public RoleDataSeed(ISqlSugarRepository<RoleAggregateRoot> repository) => _repository = repository;
	#endregion

	#region 成员属性
	private ISqlSugarRepository<RoleAggregateRoot> _repository;
	#endregion

	#region 自身方法
	public async Task SeedAsync(DataSeedContext context) { if (!await _repository.IsAnyAsync(x => true)) await _repository.InsertManyAsync(GetSeedData()); }

	private List<RoleAggregateRoot> GetSeedData()
	{
		var entities = new List<RoleAggregateRoot>();
		entities.AddRange([
			new() { RoleName = "管理员", RoleCode = "admin", DataScope = DataScopeEnum.ALL, OrderNum = 999, Remark = "管理员", IsDeleted = false, State = true },
			new() { RoleName = "默认角色", RoleCode = "default", DataScope = DataScopeEnum.ALL, OrderNum = 1, Remark = "可简单浏览", IsDeleted = false, State = true },
		]);
		return entities;
	}
	#endregion
}
